package org.lanqiao.tjut.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.lanqiao.tjut.bean.UsersBean;

import com.sun.net.httpserver.HttpsServer;

public class CheckLogin implements Filter {

	@Override
	public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain chain)
			throws IOException, ServletException {
		// 过滤器业务处理操作
		// 1.获取用户的登录信息（从session缓存获取）
		HttpServletRequest request = (HttpServletRequest) arg0;
		UsersBean LoginedUserB = (UsersBean) request.getSession().getAttribute("LoginedUserB");
		// 2.验证用户信息是否合法

		// 3.验证结果跳转处理
		if (LoginedUserB != null) {
			// 验证合法

			// 4.继续转发控制链
			chain.doFilter(arg0, arg1);
		} else {
			// 验证失败(重定向到登录页面)
			((HttpServletResponse) arg1).sendRedirect("./../Login.jsp");
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		// 初始化设置

	}

	@Override
	public void destroy() {
		// 销毁处理

	}
}
